<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-07-01 11:17
 *
 * Version: 2.0
 */

namespace App\Models;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class AuthRule extends Model
{
	use AdminBuilder, ModelTree {
		ModelTree::boot as treeBoot;
	}

	protected $guarded=[];

	public function roles() : BelongsToMany
	{
		return $this->belongsToMany(Role::class, 'role_auth_rule', 'auth_rule_id', 'role_id');

	}


	public function __construct(array $attributes = [])
	{
		$this->setTable('auth_rule');
		parent::__construct($attributes);
		$this->setTitleColumn('name');
	}


	/**
	 * Detach models from the relationship.
	 *
	 * @return void
	 */
	protected static function boot()
	{
		parent::boot();
		static::deleting(function ($model) {
			$model->roles()->detach();
		});
	}

}